﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Xml.Serialization;

namespace UpdaterForm
{
    [Serializable]
    public class Data
    {
        [XmlArrayItem(typeof (AppData))]
        public List<AppData> AppData { get; set; }


        public AppData GetByName(String name)
        {
            try
            {
                return AppData.First(x => x.AppName.Equals(name));
            }
            catch (Exception)
            {
                return null;
            }
        }

        public AppData GetByInstallPath(String Path)
        {
            try
            {
                return AppData.First(x => Path.Contains(x.InstallationPath));
            }
            catch (Exception)
            {
                return null;
            }
        }

        public void Add(AppData data)
        {
            bool contains = false;
            foreach (AppData appData in AppData)
            {
                if (appData.AppName.Equals(data.AppName))
                {
                    contains = true;
                    break;
                }
            }

            if (!contains)
            {
                AppData.Add(data);
            }
        }
    }
}